using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public enum MagicType
{
    normal,
    skill3
}
public class Magic : MonoBehaviour
{
    private RaycastHit hitInfo;
    private Vector3 target;
    public float speed;
    public MagicType magicType;
    private AttackData_SO attackData;
    
    private void Awake()
    {
        attackData = GameManager.Instance.playerStats.attackData;
        if (magicType == MagicType.normal)
        {
            target = FindObjectOfType<MageController>().GetComponent<MageController>().targetPos;
            transform.DOMove(target, (Vector3.Distance(target, transform.position) / speed)).SetEase(Ease.Linear);
            Destroy(this.gameObject, 5f);
        }

        if (magicType == MagicType.skill3)
        {
            Destroy(gameObject,10f);
        }
    }
    
    private void Update()
    {
        if (magicType == MagicType.skill3)
        {
            transform.RotateAround(GameManager.Instance.playerStats.transform.position,Vector3.up,1f);
        }
    }
    
    private void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.CompareTag("Enemy"))
        { 
            var collisionStats = other.gameObject.GetComponent<CharacterStats>();
            collisionStats.TakeDamage((int)(attackData.maxDamage), collisionStats);
            Destroy(this.gameObject);
        }
    }

}
